import React from 'react';
import useAmis from '@/uses/useAmis';
import { createResourceCrudTable } from '@/utils/amisUtils';

export default () => {
  const json = createResourceCrudTable({
    resourceName: 'shop',
    detailColumns: [{
      "type": "input-text",
      "name": "name",
      "label": "店铺名称"
    },
    {
      "type": "select",
      "source": "${shopPlatformList}",
      "name": "shopPlatform",
      "label": "平台"
    }],
    itemColumns:[
      {
        "name": "name",
        "label": "名称",
        "sortable": true,
        "searchable": {
          "type": "input-text",
          "placeholder": "请输入",
          "mode": "horizontal"
        }
      },
      {
        "name": "shopPlatform",
        "label": "平台",
        "sortable": true,
        "type": "mapping",
        "labelField": "label",
        "valueField": "value",
        "source": "${shopPlatformList}",
        "searchable": {
          "type": "select",
          "source": "${shopPlatformList}",
          "mode": "horizontal",
          "clearable": true,
        }
      }
    ],
  });

  const AmisComponent = useAmis({
    "type": "page",
    "initApi": {
      "url": "/api/v1/shop/shopPlatformList",
      "method": "post",
      "responseData": {
        "shopPlatformList": "${items}",
      }
    },
    "body": [
      // {
      //   "type": "static",
      //   "name": "${shopPlatformList|json}",
      //   "label": "选中的值是"
      // },
      json
    ]
  });

  return (
    <div>
      <AmisComponent/>
    </div>
  )
}